Imports System
Imports System.Xml

Public Class TradeStatusMsg
	Inherits BaseMsg

	Protected m_rpttype As String	' 0 = Submit, 2 = Accept, 3 = Decline, 6 = Trade Report Cancel
	Protected m_transtype As String	' 0=new, 1=cancel
	Protected m_lastpx As String	' trade price per contract
	Protected m_lastqty As String	' trade quantity

	Protected m_cfi As String	' security type: FXXXX=Future, OPXXXX=Option Put, OCXXXX=Option Call, M=Multi-leg
	Protected m_tmunit As String	'time/term of uom: s=second, min=minute, h=hour, d=day, wk=week, mo=month, yr=year
	Protected m_mmy As String	' maturity month day
	Protected m_strk As String	' strike price
	Protected m_uom As String	' unit of measure - DO WE NEED?

	' if this is a Strip trade (more than 1 month), we will have leg 2 data
	Protected m_leg2mmy As String = ""
	Protected m_leg2strk As String
	Protected m_leg2cfi As String
	Protected m_leg2tmunit As String
	Protected m_leg2uom As String

	Protected m_execid As String
	Protected m_exectype As String

	Protected m_buyer As New ReportSide(RptSides.Buy)
	Protected m_seller As New ReportSide(RptSides.Sell)

#Region "properties"

	Public Property ReportType() As String
		Get
			Return m_rpttype
		End Get
		Set(ByVal Value As String)
			m_rpttype = Value
		End Set
	End Property

	Public Property TransType() As String
		Get
			Return m_transtype
		End Get
		Set(ByVal Value As String)
			m_transtype = Value
		End Set
	End Property

	Public Property TradePrice() As String
		Get
			Return m_lastpx
		End Get
		Set(ByVal Value As String)
			m_lastpx = Value
		End Set
	End Property

	Public Property TradeQuantity() As String
		Get
			Return m_lastqty
		End Get
		Set(ByVal Value As String)
			m_lastqty = Value
		End Set
	End Property

	Public Property FirstCFI() As String
		Get
			Return m_cfi
		End Get
		Set(ByVal Value As String)
			m_cfi = Value
		End Set
	End Property

	Public Property FirstTmUnit() As String
		Get
			Return m_tmunit
		End Get
		Set(ByVal Value As String)
			m_tmunit = Value
		End Set
	End Property

	Public Property FirstMMY() As String
		Get
			Return m_mmy
		End Get
		Set(ByVal Value As String)
			m_mmy = Value
		End Set
	End Property

	Public Property FirstStrikePrice() As String
		Get
			Return m_strk
		End Get
		Set(ByVal Value As String)
			m_strk = Value
		End Set
	End Property

	Public Property FirstUOM() As String
		Get
			Return m_uom
		End Get
		Set(ByVal Value As String)
			m_uom = Value
		End Set
	End Property

	Public Property LastCFI() As String
		Get
			Return m_leg2cfi
		End Get
		Set(ByVal Value As String)
			m_leg2cfi = Value
		End Set
	End Property

	Public Property LastTmUnit() As String
		Get
			Return m_leg2tmunit
		End Get
		Set(ByVal Value As String)
			m_leg2tmunit = Value
		End Set
	End Property

	Public Property LastMMY() As String
		Get
			Return m_leg2mmy
		End Get
		Set(ByVal Value As String)
			m_leg2mmy = Value
		End Set
	End Property

	Public Property LastStrikePrice() As String
		Get
			Return m_leg2strk
		End Get
		Set(ByVal Value As String)
			m_leg2strk = Value
		End Set
	End Property

	Public Property LastUOM() As String
		Get
			Return m_leg2uom
		End Get
		Set(ByVal Value As String)
			m_leg2uom = Value
		End Set
	End Property

	Public Property ExecID() As String
		Get
			Return m_execid
		End Get
		Set(ByVal Value As String)
			m_execid = Value
		End Set
	End Property

	Public Property ExecType() As String
		Get
			Return m_exectype
		End Get
		Set(ByVal Value As String)
			m_exectype = Value
		End Set
	End Property

	Public Sub BuyerData(ByVal customerid As String, ByVal clearingid As String, ByVal traderid As String)
		m_buyer.CustomerID = customerid
		m_buyer.ClearingID = clearingid
		m_buyer.TraderID = traderid
	End Sub

	Public Sub SellerData(ByVal customerid As String, ByVal clearingid As String, ByVal traderid As String)
		m_seller.CustomerID = customerid
		m_seller.ClearingID = clearingid
		m_seller.TraderID = traderid
	End Sub

#End Region

	'<FIXML v="4.4" s="20040109" r="20030618">
	'      <TrdCaptRptReq ReqID="my request" ReqTyp="1" ExecID="47102">
	'            <Hdr TID="NYMEX" TSub="cpcapi"/>
	'      </TrdCaptRptReq>
	'</FIXML>
	'<FIXML v="4.4" s="20040109" r="20030618">
	'      <TrdCaptRpt RptID="UNIQUE-RPTID-1" ReqID="my request" ExecTyp="F" ExecID="47102" TotNumTrdRpts="1" LastRptReqed="Y" PrevlyRpted="N" LastPx="0.1000" LastQty="10000" QtyTyp="2" TrdDt="2007-05-03" TxnTm="2007-05-03T12:00:22.000-04:00" TrnsfrRsn="Trade submitted for clearing">
	'            <Hdr SID="NYMEX" SSub="cpcapi"/>
	'            <Instrmt ID="LN" Desc="European Natural Gas Option" UOM="MMBtu" TmUnit="mo" CFI="M"/>
	'            <TrdLeg>
	'                  <Leg ID="LN" CFI="OPXXXX" Strk="5.000" MMY="200802"/>
	'            </TrdLeg>
	'            <TrdLeg>
	'                  <Leg ID="LN" CFI="OPXXXX" Strk="5.000" MMY="200806"/>
	'            </TrdLeg>
	'            <RptSide Side="1" OrdID="UNIQUE-RPTID-1_B">
	'                  <Pty ID="gagcpcuser" R="36"/>
	'                  <Pty ID="ga_global_markets" R="7"/>
	'                  <Pty ID="ABNACCT1" R="24"/>
	'                  <Pty ID="444" R="4"/>
	'                  <Pty ID="abn" R="1"/>
	'                  <Pty ID="jjbrady" R="12"/>
	'            </RptSide>
	'            <RptSide Side="2" OrdID="UNIQUE-RPTID-1_S">
	'                  <Pty ID="gagcpcuser" R="36"/>
	'                  <Pty ID="ga_global_markets" R="7"/>
	'                  <Pty ID="FIMATACCT" R="24"/>
	'                  <Pty ID="444" R="4"/>
	'                  <Pty ID="fimat" R="1"/>
	'                  <Pty ID="cornwelld" R="12"/>
	'            </RptSide>
	'      </TrdCaptRpt>
	'</FIXML>

	Public Sub New()
		IsCPC = False
		ReportType = "0"
		TransType = "0"
		ExecID = ""
		RequestType = "TrdCaptRptReq"
		ResponseType = "TrdCaptRpt"
	End Sub

	Protected Overrides Function RequestMsg(ByRef XmlW As XmlTextWriter) As Boolean
		'<FIXML v="4.4" s="20040109" r="20030618">
		'      <TrdCaptRptReq ReqID="my request" ReqTyp="1" ExecID="47102">
		'            <Hdr TID="NYMEX" TSub="cpcapi"/>
		'      </TrdCaptRptReq>
		'</FIXML>
		XmlW.WriteStartElement("FIXML")
		XmlW.WriteAttributeString("v", "4.4")
		XmlW.WriteAttributeString("s", "20040109")
		XmlW.WriteAttributeString("r", "20030618")

		XmlW.WriteStartElement("TrdCaptRptReq")
		XmlW.WriteAttributeString("ReqID", UID)
		XmlW.WriteAttributeString("ReqTyp", "1")
		XmlW.WriteAttributeString("ExecID", ExecID)

		XmlW.WriteStartElement("Hdr")
		XmlW.WriteAttributeString("TID", "NYMEX")
		XmlW.WriteAttributeString("TSub", "cpcapi")
		XmlW.WriteEndElement()

		XmlW.WriteEndElement()		 'TrdCaptRptReq
		XmlW.WriteEndElement()		 'FIXML
		Return True
	End Function

	Protected Sub CheckFor(ByRef node As XmlNode, ByVal str As String)
		If Not node.Attributes(str) Is Nothing Then
			m_errmsg = node.Attributes(str).InnerText.ToString
		End If

	End Sub

	Protected Overrides Sub ResponseParse(ByRef node As XmlNode)
		CheckFor(node, "RptRejRsn")
		CheckFor(node, "Txt")
		CheckFor(node, "TrnsfrRsn")

        If m_errmsg <> "" Then
            If m_errmsg = "Trade submitted for clearing" Then
                m_errmsg = ""
            Else
                Exit Sub
            End If
        End If
        
        '		If Not node.Attributes("RptRejRsn") Is Nothing Or Not node.Attributes("Txt") Is Nothing Or Not node.Attributes("") Is Nothing Then
        '		m_errmsg = node.Attributes("Txt").InnerText.ToString
        '		Exit Sub
        '		End If

        m_execid = node.Attributes("ExecID").InnerText.ToString
        m_exectype = node.Attributes("ExecTyp").InnerText.ToString
        '      <TrdCaptRpt RptID="UNIQUE-RPTID-1" ReqID="my request" ExecTyp="F" ExecID="47102" TotNumTrdRpts="1" LastRptReqed="Y" PrevlyRpted="N" LastPx="0.1000" LastQty="10000" QtyTyp="2" TrdDt="2007-05-03" TxnTm="2007-05-03T12:00:22.000-04:00" TrnsfrRsn="Trade submitted for clearing">
	End Sub

End Class
